package com.desire.homework;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.*;

public class _12_双色球 {
    public static void main(String[] args) throws IOException {
// 编写双色球效果
        Random rand = new Random();
// 生成蓝色 1 （1-16）
        int blue = rand.nextInt(16) + 1;
// 生成红色 5 （1-33）   set集合 具有去重功能
        Set<Integer> reds = new HashSet<>();
        while (reds.size() < 5) {
            reds.add(rand.nextInt(33) + 1);
        }
        System.out.println(reds);
        System.out.println(blue);
        List<Integer> list = new ArrayList<Integer>(reds);
        list.sort((a, b) -> a - b);
        list.add(blue);
        System.out.println(list);

        // 画图
        BufferedImage i = new BufferedImage(350, 100, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = i.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setFont(new Font("", Font.BOLD, 25));
        g.setStroke(new BasicStroke(3));
        for (int n = 0; n < list.size(); n++) {
            g.setColor(Color.BLUE);
            int x = n * 55 + 12;
            int y = 28;
            String sc = String.format("%02d", list.get(n));
            if (n < 5) {
                g.setColor(Color.RED);
                g.drawOval(x, y, 50, 50);
                g.drawString(sc, x + 12, y + 33);
                continue;
            }
            g.drawOval(x, y, 50, 50);
            g.drawString(sc, x + 12, y + 33);
        }
        g.dispose();
        ImageIO.write(i, "png", new FileOutputStream("C:\\Users\\desire\\Desktop\\javaProject\\01-javaBase\\src\\main\\resources\\ok.png"));
        Runtime run = Runtime.getRuntime();
        run.exec("cmd /k start C:\\Users\\desire\\Desktop\\javaProject\\01-javaBase\\src\\main\\resources\\ok.png");
    }
}
